//
//  DSPStatusListViewModel.swift
//  SWweibo
//
//  Created by 杜守鹏 on 16/1/3.
//  Copyright © 2016年 杜守鹏. All rights reserved.
//

import UIKit

class DSPStatusListViewModel: NSObject {
     var StatusArr:[DSPStatusViewModel]?
    
    func loadData(complete:(isSucceed:Bool)->()){
        
        let urlString = "https://api.weibo.com/2/statuses/friends_timeline.json"
        var dict = [String:AnyObject]()
        dict["access_token"] = DSPDSPUserCountViewModel.account()?.access_token
//        print(DSPDSPUserCountViewModel.account()?.access_token)
        DSPNetTools.sharedTools.getRequest(urlString, parameters: dict) { (response, error) -> () in
            if error != nil {
                print(error)
                complete(isSucceed: false )
                return
            }
            
            guard let responseDic = response as? [String:AnyObject] else{
                print("不是字典")
                complete(isSucceed: false )
                return
            }
            var tempArr :[DSPStatusViewModel] = [DSPStatusViewModel]()
            
            let statusDic = responseDic["statuses"]! as! [[String: AnyObject]]
            
            for dict in statusDic {
                let status = DSPStatus(dict: dict)
                let statusModel = DSPStatusViewModel()
                statusModel.status = status
                tempArr.append(statusModel)
            }
            self.StatusArr = tempArr
           complete(isSucceed: true)
          
        }

    }
}
